package com.apes.pi.service;

import com.apes.framework.api.DomainService;
import com.apes.framework.plugin.esb.api.SimpleRequest;
import com.apes.pi.model.PiConnector;
import com.apes.pi.model.Sender;
import com.apes.pi.model.SenderParams;
import com.apes.pi.repository.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 连接器服务类
 *
 * @author wuq
 * @create 2019-10-22 15:38
 */
@Service
public class SenderService extends DomainService {

    @Autowired
    SenderRepository senderRepository;
    @Autowired
    SenderParamsRepository senderParamsRepository;

    @Autowired
    PipeRepository pipeRepository;
    @Autowired
    PipeParamsRepository pipeParamsRepository;


    public Sender create(SimpleRequest request){
        Sender sender = request.getO(Sender.class);
        for (SenderParams item : sender.getParams()) {
            item.setSender(sender);
        }
        return senderRepository.saveAndFlush(sender);
    }

    public Sender update(SimpleRequest request){
        Sender sender = request.getO(Sender.class);
        for (SenderParams item : sender.getParams()) {
            item.setSender(sender);
        }
        return senderRepository.saveAndFlush(sender);
    }

    public String delete(SimpleRequest request){
        Sender sender = request.getO(Sender.class);
        senderRepository.delete(sender);
        return "删除成功";
    }
}
